package com.umer.pinban.adapter.data;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;
import com.common.ui.recycleview.adapter.RecyclerviewBasicAdapter;
import com.common.ui.recycleview.base.ViewHolder;
import com.common.ui.recycleview.listener.OptListener;
import com.umer.pinban.R;
import com.umer.pinban.bean.data.DataDictionaryBean;
import java.util.List;

/**
 * 数据字典
 */
public class DataDictionnaryAdapter extends RecyclerviewBasicAdapter<DataDictionaryBean> {

    private OptListener optListener;

    public DataDictionnaryAdapter(Context context, List<DataDictionaryBean> datas, int layoutId,
                                  OptListener optListener) {
        super(context, datas, layoutId);
        this.optListener = optListener;
    }

    @Override
    public void convert(ViewHolder holder, final DataDictionaryBean dataDictionaryBean, final int position) {
        TextView tv = holder.getView(R.id.tv);
        String lable = dataDictionaryBean.getLabel();
        if(lable.equals("转介绍")){
            if(dataDictionaryBean.isSelect()){
                tv.setText(dataDictionaryBean.getCustomerName()+"("+"转"+")");
            }else {
                tv.setText(lable);
            }
        }else {
            tv.setText(lable);
        }
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                optListener.onOptClick(v,position);
            }
        });
        boolean select = dataDictionaryBean.isSelect();
        if(select){
            tv.setTextColor(Color.parseColor("#ffffff"));
            tv.setBackgroundColor(Color.parseColor("#C2242B"));
        }else {
            tv.setTextColor(Color.parseColor("#181818"));
            tv.setBackgroundColor(Color.parseColor("#D9D7D7"));
        }
    }
}
